package user

import (
	"github.com/bgmp/config"
	"github.com/bgmp/middleware"
	"github.com/bgmp/model"
	"github.com/gin-gonic/gin"
	"time"
)

func (b Base) GetCaseHistory(c *gin.Context, req *GetCaseHistoryRequest) *GetCaseHistoryResponse {
	ch := &model.CaseHistory{}
	ch.UserId = middleware.GetUserId(c)
	err := ch.Get(config.DB)
	if err != nil {
		return &GetCaseHistoryResponse{}
	}
	view := model.FormatCaseHistoryView(ch)
	return &GetCaseHistoryResponse{
		Gender:    view.Gender,
		Age:       view.Age,
		Height:    view.Height,
		Weight:    view.Weight,
		BMI:       view.Weight / view.Height,
		DmType:    view.DmType,
		Diagnosis: view.Diagnosis,
		Duration:  time.Now().Year() - view.Diagnosis,
		Note:      view.Note,
	}
}

type GetCaseHistoryRequest struct {
}

type GetCaseHistoryResponse struct {
	Gender    string  `json:"gender"`
	Age       int     `json:"age"`
	Height    float64 `json:"height"`
	Weight    float64 `json:"weight"`
	BMI       float64 `json:"bmi"`
	DmType    string  `json:"dmType"`
	Diagnosis int     `json:"diagnosis"`
	Duration  int     `json:"duration"`
	Note      string  `json:"note"`
}
